﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>PixelSearch - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The PixelSearch function searches a region of the screen for a pixel of the specified color." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>PixelSearch</h1>

<p>Searches a region of the screen for a pixel of the specified color.</p>

<pre class="Syntax"><span class="func">PixelSearch</span> OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID <span class="optional">, Variation</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>OutputVarX/Y</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#variables">变量</a></p>
    <p>The variables in which to store the X and Y coordinates of the first pixel that matches <em>ColorID</em> (if no match is found, the variables are made blank). Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that.</p>
  </dd>

  <dt>X1, Y1</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The X and Y coordinates of the starting corner of the rectangle to search. <strong>Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that</strong>.</p>
  </dd>

  <dt>X2, Y2</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The X and Y coordinates of the ending corner of the rectangle to search. Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that.</p>
  </dd>

  <dt>ColorID</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The color ID to search for. This is typically expressed as a hexadecimal number in red-green-blue (RGB) format. 例如: <code>0x9d6346</code>. Color IDs can be determined using Window Spy (accessible from the tray menu) or via <a href="PixelGetColor.htm">PixelGetColor</a>.</p>
  </dd>

  <dt>Variation</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>A number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of the color. This parameter is helpful if the color sought is not always exactly the same shade. If you specify 255 shades of variation, all colors will match. The default is 0 shades.</p>
  </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#boolean">整数(布尔值)</a></p>
<p>This function returns 1 (true) if the color was found in the specified region, or 0 (false) if it was not found.</p>

<h2 id="Error_Handling">错误处理</h2>
<p>An exception is thrown if there was a problem that prevented the function from conducting the search.</p>

<h2 id="Remarks">备注</h2>
<p>The region to be searched must be visible; in other words, it is not possible to  search a region of a window hidden behind another window. By contrast, pixels beneath the mouse cursor can usually be detected. The exception to this is cursors in games, which in most cases will hide any pixels beneath them.</p>
<p>Although color depths as low as 8-bit (256-color) are supported, the fast mode performs much better in 24-bit or 32-bit color.</p>
<p>The search starts at the coordinates specified by <em>X1</em> and <em>Y1</em> and checks all pixels in the row from <em>X1</em> to <em>X2</em> for a match. If no match is found there, the search continues toward <em>Y2</em>, row by row, until it finds a matching pixel.</p>
<p>The search order depends on the order of the parameters. In other words, if <em>X1</em> is greater than <em>X2</em>, the search will be conducted from right to left, starting at column <em>X1</em>. Similarly, if <em>Y1</em> is greater than <em>Y2</em>, the search will be conducted from bottom to top.</p>
<p>If the region to be searched is large and the search is repeated with high frequency, it may consume a lot of CPU time. To alleviate this, keep the size of the area to a minimum.</p>

<h2 id="Related">相关</h2>
<p><a href="PixelGetColor.htm">PixelGetColor</a>, <a href="ImageSearch.htm">ImageSearch</a>, <a href="CoordMode.htm">CoordMode</a>, <a href="MouseGetPos.htm">MouseGetPos</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>if PixelSearch(Px, Py, 200, 200, 300, 300, 0x9d6346, 3)
    MsgBox "A color within 3 shades of variation was found at X" Px " Y" Py
else
    MsgBox "That color was not found in the specified region."
</pre>
</div>

</body>
</html>